#include "renrendailogin.h"
#include "renrendaigetlist.h"
//#include "renrendaigetdetail.h"
#include "renrendai.h"
#include "gumbo.h"

static char buf[102400];
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int readfile(char *filename)
{
	int ret = 0;
	struct stat st;
	ret = stat(filename, &st);
	long len = 0;
	int fd = open(filename, O_RDONLY);
	while (len < st.st_size) {
		int r = read(fd, buf + len, 1000);
		len += r;
	}
	return 0;
}
int RenrendaiGetList_RespProcFunc(struct HttpReq* env)
{
	int ret = 0;
	Buf *body = NULL;
	GumboOutput *output = NULL;
	Buf *jsontext = NULL;

	if (!env || !env->recvbody) {
		ErrorLog(__FILE__, __LINE__, "args is null");
		return SPIDER_ARG_ERR;
	}
	body = env->recvbody;
	output=gumbo_parse(body->base);

	if(!output)
	{
		ErrorLog(__FILE__, __LINE__, "gumbo_parse failed");
		return SPIDER_INTERNAL_ERR;
	}
	jsontext = InitBuf(10240);
	if (!jsontext || !jsontext->base) {
		ErrorLog(__FILE__, __LINE__, "InitBuf error");
		ret = SPIDER_MEM_ERR;
	}
	Get_JsonText(output->root, GUMBO_TAG_SCRIPT, RENRENDAIJSONLISTID, jsontext);

	if (jsontext->usedlen == 0) {
		ErrorLog(__FILE__, __LINE__, "failed json text success!");
	}
	return 0;
}

int testgetlist()
{
	struct HttpReq req;
	GumboOutput *output = NULL;
	char orgattrvalue[101];
	int i = 0;
	int ret = 0;
	Buf b;

	memset(buf, 0x00, sizeof(buf));
	readfile("debitlist");

	b.base = buf;
	req.recvbody = &b;
//	ParsePageCntAndDebitList(&req);
	RenrendaiGetList_RespProcFunc(&req);
}
int main()
{
	//test();
	//	testparse();
	//testparsedetailusr();
	// testparserecord();
	//testparseuser();
	//testenum();
	//testparsejson();
	testgetlist();
}

